package com.globalwave.pos.inventory;


import org.junit.Test;

import com.globalwave.common.cache.CodeHelper;
import com.globalwave.common.exception.BusinessException;
import com.globalwave.pos.inventory.service.ProductItemBO;

import junit.framework.Assert;


public class ItemMasterPriceBOTest extends InventoryBaseTestCase {
    private Long itemNumber = 12345L ;
    
    @Override
    public void initDataForMethod() throws Exception {
    	super.initDataForMethod() ;
    	CodeHelper.reload("Product") ;
    }


    @Test
    public void validateSalable_notExist() throws Exception {
    	try {
    		ProductItemBO bo = getItemBO();
        	bo.get(itemNumber) ;
        	//bo.validateItemPriceSalable(new Date());
			Assert.assertTrue("BusinessException should be throwed!", false) ;
		} catch (BusinessException e) {
			Assert.assertEquals("201000", e.getMessageKey()) ;
		}
    }

    @Test
    public void validateSalable_20110905() throws Exception {
    	Long d20110905000000 = 20110905000000L ;
    	Long d20110905000001 = 20110905000001L ;
    	Long d20110904235959 = 20110904235959L ;
    	
    	ProductItemBO bo = getItemBO();
    	
    	try {
        	bo.validateSalable(itemNumber, d20110905000000, 101) ;
			Assert.assertTrue("Pos5gBizException should be throwed!", false) ;
		} catch (BusinessException e) {
			Assert.assertEquals("err.inv.item.no.percentage", e.getMessageKey()) ;
		}
		
    	//bo.retrieveItemPrice(itemNumber, null) ;
    	try {
    	    bo.validateSalable(itemNumber, d20110905000000);
		} catch (BusinessException e) {
			Assert.assertTrue("Pos5gBizException should not be throwed!", false) ;
		}
    	try {
    		bo.validateSalable(itemNumber, d20110905000001);
		} catch (BusinessException e) {
			Assert.assertTrue("Pos5gBizException should not be throwed!", false) ;
		}
    	try {
    		bo.validateSalable(itemNumber, d20110904235959);
			Assert.assertTrue("Pos5gBizException should be throwed!", false) ;
		} catch (BusinessException e) {
			Assert.assertEquals("err.inv.item.unsalable", e.getMessageKey()) ;
		}
    }


    private ProductItemBO getItemBO() {
    	return new ProductItemBO() ;
    }
}
